<?php
class User_model extends CI_Model{
	function User_model(){
		parent::__construct();
	}
	
	public function register($content){
		$data = array(
			'username' => $content['user'],
			'password' => $content['pass'],
			'firstname' => $content['fname'],
			'lastname' => $content['lname'],
			'type' => '2',
			'public' => '1'
		);
		
		$this->db->insert('users',$data);
		
		$q = $this->db->get_where('users',array('username' => $data['username']));
		
		if($q->num_rows()){
			
			$row = $q->row_array();
			
			$data = array(
				'address' => $content['address'],
				'district' => $content['district'],
				'city' => $content['city'],
				'state' => NULL,
				'country' => $content['country'],
				'email' => $content['email'],
				'user_id' => $row['id']
			);	
			
			$this->db->insert('address',$data);
		}
	}
	
	public function validate_login($username,$password){
		$result = $this->db->get_where('users',array('username' => $username, 'password' => md5($password)));
		
		$data = $result->num_rows();
		$result->free_result();

		if($data > 0)
			return TRUE;
		return FALSE;
	}
}
